package com.test;

import com.config.SpringConfiguration;
import com.entity.Person;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.internal.Classes;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)//指定Junit4使用Spring提供的测试环境
@ContextConfiguration(classes={SpringConfiguration.class})
public class SpringIocAnnocation {
    private static AnnotationConfigApplicationContext context;

    @BeforeClass
    public static void initContext(){
        context = new AnnotationConfigApplicationContext(SpringConfiguration.class);
    }

    @Test
    public void test(){
        Person person = (Person) context.getBean("p1");
        System.out.println(person);
    }
}
